package com.suanfa.collect;

/**
 * @author jukg
 * @date 2025/01/10 17:39
 * @description 王者分队伍，队伍武力差值最小值
 */
public class Wangzhe {


    static int min = Integer.MAX_VALUE;
    static int totalNum = 0;
    static int targetSum = 0;

    public static void main(String[] args) {
        int[] members = {1,2,3,4,5,6,7,8,9,10};
        System.out.println(min(members));
    }
    public static int min(int[] members){


        for(int s: members){
            totalNum += s;
        }

        dfs(members, 0, 0, 0);

        return min;

    }

    public static void dfs(int[] members, int index, int count, int sum){
        //本队最后一个队员招纳完
        if(count == 5){
            targetSum = totalNum - sum;
           min = Math.min(min, Math.abs(sum-targetSum));
           return;
        }
        //都放到一个队直接退出
        if(index == 10) return;
        int mem = members[index];
        //当前队员归属
        dfs(members, index++, count++, sum+ mem);
        //当前队员归属对方
        dfs(members, index++, count, sum);

    }
}
